<?php
$productName=$_REQUEST["productName"];
$image=$_FILES["image"];
$file=fopen($image["tmp_name"],"rb");
$length=filesize($image["tmp_name"]);
$content=fread($file,$length);
$content=addslashes($content);
fclose($file);

function getConn() {
    $url = "localhost:3306";
    $user = "root";
    $password = "";// 如果没有密码, 就是空字符串
    $database = "php";
    $conn = mysqli_connect($url, $user, $password, $database);
    mysqli_query($conn, "set names utf8");
    return $conn;
}

$conn=getConn();
$sql="insert into product (p_name,p_image) values ('{$productName}','{$content}')";
$result=mysqli_query($conn,$sql);
if($result){
    echo "<div>商品添加成功</div>";
}else{
    $msg = mysqli_error($conn);
    echo "<div>商品添加失败:{$msg}</div>";
}
?>